package cmd

import (
	"github.com/spf13/cobra"

	"go-cli/utils"

	"go-cli/internal/myapp"
)

var newCommand = &cobra.Command{
	Use: "new",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 0 {
			cmd.Println(cmd.Help())
			return
		}

		exists, err := utils.DirectoryExists(args[0])
		if err != nil {
			cmd.Print("error while executing command\n")
		}
		if exists {
			cmd.PrintErrf("directory % already exists\n", args[0])
			return
		}

		app := myapp.NewApp("foo")

		err = app.Generate(cmd.Context())
		if err != nil {
			panic(err)
		}
	},
	Example: "go-cli new <directory> <flags>",
}

func init() {
	rootCommand.AddCommand(newCommand)
	newCommand.PersistentFlags().StringP(
		"mod",
		"m",
		"",
		"set the mod path for your cli project",
	)
	newCommand.Flags().Bool("monolith", false, "to use the architecture as monolith project")
}
